package com.yyx.Imitate;

import com.yyx.mapper.TestMapper;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class MyImportBeanDefinitionRegister implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

        /**
         * 得到bd
         */
        BeanDefinitionBuilder builder=BeanDefinitionBuilder.genericBeanDefinition(TestMapper.class);
        GenericBeanDefinition beanDefinition = (GenericBeanDefinition) builder.getBeanDefinition();

        //通过构造方法生成bd
        beanDefinition.getConstructorArgumentValues().addGenericArgumentValue("com.yyx.mapper.TestMapper");
        beanDefinition.setBeanClass(MyFactoryBean.class);
        //注册入beanFactory
        registry.registerBeanDefinition("testMapper",beanDefinition);
    }
}
